<template>
  <div v-if="isShow">
    <label>聚合子账号数据: &nbsp;</label>
    <el-switch
    v-model="yesOrNo"
    @change="handleSetsSubAccount"
    active-color="#13ce66"
    inactive-color="grey">
  </el-switch></div>

</template>

<script>
export default {
  name: 'SubAccountDataSetting',
  data() {
    return {
      yesOrNo:false
    }
  },
  computed: {
    isShow() {
      return !this.$store.getters.isAdmin
    }
  },
  created() {
    this.yesOrNo = this.$store.getters.showSubData
  },
  methods: {
    handleSetsSubAccount() {
      this.$store.dispatch('user/setSubAccountData', this.yesOrNo)
      this.refreshView()
    },
    refreshView() {
      // In order to make the cached page re-rendered
      this.$store.dispatch('tagsView/delAllCachedViews', this.$route)

      const { fullPath } = this.$route

      this.$nextTick(() => {
        this.$router.replace({
          path: '/redirect' + fullPath
        })
      })
    }
  }

}
</script>
